﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;

namespace Abhiruchi_Phase1
{
    class CommunicationDAL
    {
        public static SqlConnection myCon = new SqlConnection(App.ConnectionString);
        public static SqlCommand myCom;
        public static void CreateCommunication(string Eid, string PeAd_HouseNo, string PeAd_Street, string PeAd_City, string PeAd_State, string PeAd_Pincode, string PeAd_District, string PrAd_HouseNo, string PrAd_Street, string PrAd_City, string PrAd_State, string PrAd_Pincode, string PrAd_District, string MobileHome, string MobileWork, string LandlineHome, string LandlineWork, string FCN, string FCNRelation, string FCRelationName, string PersonalEmail, string OfficialEmail, int type)
        {
            SqlCommand myCom = new SqlCommand();
            myCom.Connection = myCon;
            myCom.CommandText = "sp_HRM_Get_Set_PE_CE_CommunicationInfo";
            myCom.CommandType = CommandType.StoredProcedure;

            myCom.Parameters.AddWithValue("@Eid", Eid);
            myCom.Parameters.AddWithValue("@PeAd_HouseNo", PeAd_HouseNo);
            myCom.Parameters.AddWithValue("@PeAd_Street", PeAd_Street);
            myCom.Parameters.AddWithValue("@PeAd_City", PeAd_City);
            myCom.Parameters.AddWithValue("@PeAd_District", PeAd_District);
            myCom.Parameters.AddWithValue("@PeAd_State", PeAd_State);
            myCom.Parameters.AddWithValue("@PeAd_Pincode", PeAd_Pincode);
           
            myCom.Parameters.AddWithValue("@PrAd_HouseNo", PrAd_HouseNo);
            myCom.Parameters.AddWithValue("@PrAd_Street", PrAd_Street);
            myCom.Parameters.AddWithValue("@PrAd_City", PrAd_City);
            myCom.Parameters.AddWithValue("@PrAd_District", PrAd_District);
            myCom.Parameters.AddWithValue("@PrAd_State", PrAd_State);
            myCom.Parameters.AddWithValue("@PrAd_Pincode", PrAd_Pincode);
           
            myCom.Parameters.AddWithValue("@MobileHome", MobileHome);
            myCom.Parameters.AddWithValue("@MobileWork", MobileWork);
            myCom.Parameters.AddWithValue("@LandlineHome", LandlineHome);
            myCom.Parameters.AddWithValue("@LandlineWork", LandlineWork);
            myCom.Parameters.AddWithValue("@FCN", FCN);
            myCom.Parameters.AddWithValue("@FCNRelation", FCNRelation);
            myCom.Parameters.AddWithValue("@FCRelationName", FCRelationName);
            myCom.Parameters.AddWithValue("@PersonalEmail", PersonalEmail);
            myCom.Parameters.AddWithValue("@OfficialEmail", OfficialEmail);
            myCom.Parameters.AddWithValue("@int_ProcessType", type);

            try
            {
                myCon.Open();
                myCom.ExecuteNonQuery();
            }
            catch (Exception)
            {
            }
            finally
            {
                myCon.Close();
            }
        }
        public static DataTable LoadCommDataFromDB(string Eid, int type)
        {
            SqlCommand myCom = new SqlCommand();
            myCom.Connection = myCon;
            myCom.CommandText = "sp_HRM_Get_Set_PE_CE_CommunicationInfo";
            myCom.CommandType = CommandType.StoredProcedure;
            myCom.Parameters.AddWithValue("@Eid", Eid);
            myCom.Parameters.AddWithValue("@int_ProcessType", type);
            DataTable myDt = new DataTable();

            SqlDataAdapter myda = new SqlDataAdapter(myCom);
            myda.Fill(myDt);
            return myDt;
        }

        public static void UpdateCommData(string Eid, string PeAd_HouseNo, string PeAd_Street, string PeAd_City, string PeAd_State, string PeAd_Pincode, string PeAd_District, string PrAd_HouseNo, string PrAd_Street, string PrAd_City, string PrAd_State, string PrAd_Pincode, string PrAd_District, string MobileHome, string MobileWork, string LandlineHome, string LandlineWork, string FCN, string FCNRelation, string FCRelationName, string PersonalEmail, string OfficialEmail, int type)
        {
            SqlCommand myCom = new SqlCommand();
            myCom.Connection = myCon;
            myCom.CommandText = "sp_HRM_Get_Set_PE_CE_CommunicationInfo";
            myCom.CommandType = CommandType.StoredProcedure;

            myCom.Parameters.AddWithValue("@Eid", Eid);
            myCom.Parameters.AddWithValue("@PeAd_HouseNo", PeAd_HouseNo);
            myCom.Parameters.AddWithValue("@PeAd_Street", PeAd_Street);
            myCom.Parameters.AddWithValue("@PeAd_City", PeAd_City);
            myCom.Parameters.AddWithValue("@PeAd_District", PeAd_District);
            myCom.Parameters.AddWithValue("@PeAd_State", PeAd_State);
            myCom.Parameters.AddWithValue("@PeAd_Pincode", PeAd_Pincode);
           
            myCom.Parameters.AddWithValue("@PrAd_HouseNo", PrAd_HouseNo);
            myCom.Parameters.AddWithValue("@PrAd_Street", PrAd_Street);
            myCom.Parameters.AddWithValue("@PrAd_City", PrAd_City);
            myCom.Parameters.AddWithValue("@PrAd_District", PrAd_District);
            myCom.Parameters.AddWithValue("@PrAd_State", PrAd_State);
            myCom.Parameters.AddWithValue("@PrAd_Pincode", PrAd_Pincode);
           
            myCom.Parameters.AddWithValue("@MobileHome", MobileHome);
            myCom.Parameters.AddWithValue("@MobileWork", MobileWork);
            myCom.Parameters.AddWithValue("@LandlineHome", LandlineHome);
            myCom.Parameters.AddWithValue("@LandlineWork", LandlineWork);
            myCom.Parameters.AddWithValue("@FCN", FCN);
            myCom.Parameters.AddWithValue("@FCNRelation", FCNRelation);
            myCom.Parameters.AddWithValue("@FCRelationName", FCRelationName);
            myCom.Parameters.AddWithValue("@PersonalEmail", PersonalEmail);
            myCom.Parameters.AddWithValue("@OfficialEmail", OfficialEmail);
            myCom.Parameters.AddWithValue("@int_ProcessType", type);

            try
            {
                myCon.Open();
                myCom.ExecuteNonQuery();
            }
            catch
            {

            }
            finally
            {

                myCon.Close();
            }

        }
    }
}